﻿using System.Runtime.Serialization;
using ProxyTool.Services;
using ProxyTool.Utils;

namespace ProxyTool.Models
{
    /// <summary>
    ///     代理对象
    /// </summary>
    [DataContract]
    public class ProxyData
    {
        /// <summary>
        ///     代理类型
        /// </summary>
        [DataMember]
        public string ProxyType { get; set; }

        /// <summary>
        ///     按数据成员(DataMember)传输数据
        /// </summary>
        [DataMember]
        public bool UseDataContract { get; set; }

        /// <summary>
        /// 请求数据最大展开深度
        /// </summary>
        [DataMember]
        public int RequestDataMaxExpandDepth { get; set; }

        /// <summary>
        ///     Json字符串
        /// </summary>
        [DataMember]
        public string ProxyJsonString { get; set; }

        /// <summary>
        ///     获取代理对象
        /// </summary>
        /// <param name="bpsvType"></param>
        /// <param name="useDataContract"></param>
        /// <param name="requestDataMaxExpandDepth"></param>
        /// <returns></returns>
        public static ProxyData GetProxyData(BPSVType bpsvType, bool useDataContract, int requestDataMaxExpandDepth)
        {
            if (bpsvType == null)
                throw new ProxyToolException("bpsvType is null");
            string proxyType = ProxyTestService.GetProxyType(bpsvType);
            if (string.IsNullOrEmpty(proxyType))
                throw new ProxyToolException("proxyType is empty");
            return ProxyTestService.GetProxyData(proxyType, useDataContract, requestDataMaxExpandDepth);
        }

        /// <summary>
        ///     获取代理对象
        /// </summary>
        /// <param name="proxyType"></param>
        /// <param name="useDataContract"></param>
        /// <param name="requestDataMaxExpandDepth"></param>
        /// <returns></returns>
        public static ProxyData GetProxyData(string proxyType, bool useDataContract,int requestDataMaxExpandDepth)
        {
            return ProxyTestService.GetProxyData(proxyType, useDataContract, requestDataMaxExpandDepth);
        }
    }
}